package com.fotoloka.view;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.util.Date;

import javax.swing.JPanel;


@SuppressWarnings("serial")
public class ImagePanel extends JPanel implements MouseListener 
{
	private Image img;
	
	private BufferedImage imgImpressao;
	
	private boolean center = true;
	
	private long tempo = new Date().getTime();
	
	public ImagePanel() {}
	
	public ImagePanel(Image img)
	{
		this.img = img;
		this.setBackground(Color.white);
	}
	
	@Override
	protected void paintComponent(Graphics g)
	{	
		long delta = (new Date().getTime() - tempo);
		tempo = new Date().getTime();
		System.out.println("Paint:" + delta);
		super.paintComponent(g);
		
		if (img == null)
			return;
		
		if (center)
		{
			Dimension size = this.getSize();
			int width = img.getWidth(this);
			int height = img.getHeight(this);
			
			g.drawImage(img, size.width / 2 - width / 2, size.height / 2 - height / 2, this);
		}
		else
		{	
			g.drawImage(img,0,0,this);
		}
	}
	
	public void setImage(Image img)
	{
		Dimension size = this.getSize();
		this.img = img.getScaledInstance(size.width, size.height, 0);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		System.out.println("mouse entered");
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		System.out.println("mouse exited");
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		System.out.println("mouse pressed");
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		System.out.println("mouse released");
		
	}
	
	public BufferedImage getImgImpressao() {
		return imgImpressao;
	}

	public void setImgImpressao(BufferedImage imgImpressao) {
		this.imgImpressao = imgImpressao;
	}

}
